package classes.managers {
	import classes.buttons.BaseButton;
	import classes.controlers.Carrot_Controler;
	import classes.controlers.Timer_Controler;
	import classes.global.Global_Properties;
	import classes.scenes.A_Scene;
	import classes.sounds.SoundCollection;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class Game_Manager extends A_Scene {
		
		// 부모클래스
		//private var main:Main;
		//private var mc:MovieClip;
		
		//객체
		private var timer:Timer_Controler;
		private var carrot:Carrot_Controler;
		
		//환경변수
		private const STAINED:int = 3;
		private const GRIND_CARROT:int = 6;
		
		private var cutLine:int = 40;
		private var count:int = 0;
		private var count2:int = 0;
		private var frameCount:int = 0;
		private var buriedCount:int = 0;
		private var carrotCount:int = 0;
		private var grindedCarrot:int = 0;
		private var grindCnt:int = 5;
		private var Hz:int;
		private var score:int = 0;
		
		private var carrotHitLock:Boolean = true;
		private var mouseAroundHit:Boolean = false;
		private var upToothHit:Boolean = false;
		private var downToothHit:Boolean = true;
		private var closedMouth:Boolean = false;
		
		private var frameCount30:int = 12;
		private var frameCount25:int = 8;
		private var frameCount20:int = 6;
		private var frameCount15:int = 4;
		private var frameCount10:int = 2;
		private var frameCount5:int = 1;
		
		private var remain30:Boolean = false;
		private var remain25:Boolean = false;
		private var remain20:Boolean = false;
		private var remain15:Boolean = false;
		private var remain10:Boolean = false;
		private var remain5:Boolean = false;
		
		private var carrotX:Number;
		private var carrotY:Number;
		
		private var mouthY:Number;
		private var buriedY:Number;
		
		//buttons
		private var startBtn:BaseButton;
		
		
		public function Game_Manager( _main:Main, _mc:MovieClip ) {
			super( _main, _mc );
			
			timer = new Timer_Controler( this, mc.timer_mc.timer_txt );
			carrot = new Carrot_Controler( this, mc.carrot_mc );
			
			mc.timeOver_mc.visible = false;
			mc.carrot_mc.arrow_mc.visible = false;
			
			carrotX = mc.carrot_mc.x;
			carrotY = mc.carrot_mc.y;
			mouthY = mc.mouth_mc.y;
			buriedY = mc.buried_mc.y;
			
			addEvent();
		}
		
		// 초기화
		public function init():void {
			carrotHitLock = true;
			mouseAroundHit = false;
			upToothHit = false;
			downToothHit = true;
			closedMouth = false;
			remain30 = false;
			remain25 = false;
			remain20 = false;
			remain15 = false;
			remain10 = false;
			remain5 = false;
			
			grindCnt = 5;
			count = 0;
			count2 = 0;
			frameCount = 0;
			buriedCount = 0;
			carrotCount = 0;
			grindedCarrot = 0;
			score = 0;
			
			mc.mouth_mc.arrow1_mc.visible = false;
			mc.mouth_mc.arrow2_mc.visible = false;
			mc.mCarrot_mc.visible = false;
			mc.carrot_mc.arrow_mc.visible = false;
			mc.carrot_mc.cursor_mc.visible = false;
			mc.timeOver_mc.visible = false;
			mc.clear_mc.visible = false;
			mc.carrotShadow_mc.visible = false;
			mc.buried_mc.gotoAndStop(1);
			mc.carrot_mc.x = carrotX;
			mc.carrot_mc.y = carrotY;
			mc.mouth_mc.y = mouthY;
			mc.buried_mc.y = buriedY;
			mc.gauge_mc.gotoAndStop(1);
			
			buriedManager(0);
			scoreInin( mc.score_mc );
			bonusInit( mc.bonus_mc.score_mc );
			
			timer.init();
			
			mc.startCount_mc.visible = true;
			mc.startCount_mc.gotoAndPlay(2);
			SoundCollection.goSound();
		}
		//게임 시작.
		private function startGame():void {
			carrot.init();
			
			mc.startCount_mc.visible = false;
			mc.mouth_mc.arrow1_mc.visible = true;
			mc.carrot_mc.arrow_mc.visible = true;
			mc.carrotShadow_mc.visible = true;
			
			mc.addEventListener(Event.ENTER_FRAME, ENTER_FRAME );
			
			
			timer.start();
		}
		
		// 이빨에 갈리는여부, 입주위에 닿았는지 여부 판단.
		private function ENTER_FRAME(e:Event):void {
			//입 닫혔다
			if ( closedMouth ) return;
			
			
			if ( carrot.shadowHit ) {
			
				// 입주위 히트 체크
				var i:int;
				var length:int = 6;
				for ( i = 1; i <= length; ++i ) {
					var check:MovieClip = mc.carrot_mc["check" + i + "_mc"];
					if ( carrotHitLock === false ) {
						
						var j:int;
						var length2:int = 8;
						for ( j = 1; j <= length2; ++j ) {
							var check2:MovieClip = mc.mouth_mc.mouthAround_mc["hitCheck_mc" + j];
							
							if ( check.hitTestObject( check2 ) ) {
								if ( mouseAroundHit === false ) {
									//trace( "hit : ", i ); 
									
									BuriedOnTheLip();
								}
								mouseAroundHit = true;
							}
						}
					}
				}
			
				// 윗이빨 당근윗부분 히트
				if ( mc.mouth_mc.tooth1_mc.hitTestObject( mc.carrot_mc.upTouch_mc ) ) {
					if ( carrotHitLock ) carrotHitLock = false;
					
					if ( upToothHit === false ) {
						if ( mouseAroundHit ) mouseAroundHit = false;
						
						upToothHit = true;
						downToothHit = false;
						
						SoundCollection.grindUpSound();
						
						if ( count2 % grindCnt === 0 ) {
							carrotCount++;
							mc.carrot_mc.gotoAndStop( carrotCount );
							if ( carrotCount === 1 ) {
								count2 = 0;
								grindCnt = 5;
							}else if ( carrotCount === 2 ) {
								count2 = 0;
								grindCnt = 4;
							}else if ( carrotCount === 3 ) {
								count2 = 0;
								grindCnt = 3;
							}else if ( carrotCount === 4 ) {
								count2 = 0;
								grindCnt = 2;
							}else if ( carrotCount === 5 ) {
								count2 = 0;
								grindCnt = 2;
							}else if ( carrotCount === 6 ) { // 당근 다 갈았을때
								grindedCarrot++;
								if ( grindedCarrot === GRIND_CARROT ) { // 당근 6개 다갈믄 클리어
									clearGame();
								}else {
									changeCarrot();
								}
							}
						}
						
						count++;
						count2++;
						score = count * 30;
						numberBoard( score, mc.score_mc );
						mc.mouth_mc.carrotChips1_mc.gotoAndPlay(2);
						mc.mouth_mc.arrow1_mc.visible = false;
						mc.mouth_mc.arrow2_mc.visible = true;
						mc.gauge_mc.gotoAndStop(count);
						mc.gauge_mc.carrotChip_mc.gotoAndPlay(1);
						mc.gauge_mc.num_txt.text = zeroFormatter( count );
					}
				}
		
				// 아래이빨 당근아래부분 히트
				if ( mc.mouth_mc.tooth2_mc.hitTestObject( mc.carrot_mc.downTouch_mc ) ) {
					if ( carrotHitLock ) carrotHitLock = false;
					
					if ( downToothHit === false ) {
						if ( mouseAroundHit ) mouseAroundHit = false;
						downToothHit = true;                                                                          
						upToothHit = false;
						
						SoundCollection.grindDownSound();
						
						if ( count2 % grindCnt === 0 ) {
							carrotCount++;
							mc.carrot_mc.gotoAndStop( carrotCount );
							if ( carrotCount === 1 ) {
								count2 = 0;
								grindCnt = 5;
							}else if ( carrotCount === 2 ) {
								count2 = 0;
								grindCnt = 4;
							}else if ( carrotCount === 3 ) {
								count2 = 0;
								grindCnt = 3;
							}else if ( carrotCount === 4 ) {
								count2 = 0;
								grindCnt = 2;
							}else if ( carrotCount === 5 ) {
								count2 = 0;
								grindCnt = 2;
							}else if ( carrotCount === 6 ) { // 당근 다 갈았을때
								grindedCarrot++;
								if ( grindedCarrot === GRIND_CARROT ) { // 당근 6개 다갈믄 클리어
									clearGame();
								}else {
									changeCarrot();
								}
							}
						}
						
						count2++;
						count++;
						score = count * 30;
						numberBoard( score, mc.score_mc );
						mc.mouth_mc.carrotChips2_mc.gotoAndPlay(2);
						mc.mouth_mc.arrow1_mc.visible = true;
						mc.mouth_mc.arrow2_mc.visible = false;
						mc.gauge_mc.gotoAndStop(count);
						mc.gauge_mc.carrotChip_mc.gotoAndPlay(1);
						mc.gauge_mc.num_txt.text = zeroFormatter( count );
					}
				}
			}
			
			frameCount++;
			//trace(frameCount % frameCount30)
			
			if ( remain30 ) if ( frameCount % frameCount30 === 0 ) mouthMoving();
			if ( remain25 ) if ( frameCount % frameCount25 === 0 ) mouthMoving();
			if ( remain20 ) if ( frameCount % frameCount25 === 0 ) mouthMoving();
			if ( remain15 ) if ( frameCount % frameCount25 === 0 ) mouthMoving();
			if ( remain10 ) if ( frameCount % frameCount25 === 0 ) mouthMoving();
			if ( remain5 )  if ( frameCount % frameCount25 === 0 ) mouthMoving();
		}
		
		private function mouthMoving():void {
			Hz *= -1;
			mc.mouth_mc.y += Hz;
			mc.buried_mc.y += Hz;
		}
		
		// 남은시간에 따른 입 움직임 설정
		public function remainTime( _remainTime:int ):void {
			mc.mouth_mc.y = mouthY;
			mc.buried_mc.y = buriedY;
			
			if ( _remainTime === 50 ) {
				//Hz = 10;
				Hz = 5;
				remain30 = true;
			}else if ( _remainTime === 40 ) {
				//Hz = 15;
				Hz = 10;
				remain30 = false;
				remain25 = true;
			}else if ( _remainTime === 30 ) {
				//Hz = 20;
				Hz = 10;
				remain25 = false;
				remain20 = true;
			}else if ( _remainTime === 20 ) {
				//Hz = 20;
				Hz = 10;
				remain20 = false;
				remain15 = true;
			}else if ( _remainTime === 10 ) {
				//Hz = 25;
				Hz = 10;
				remain15 = false;
				remain10 = true;
			}else if ( _remainTime === 5 ) {
				//Hz = 30;
				Hz = 10;
				remain10 = false;
				remain5 = true;
			}
		}
		
		//타임오버
		public function timeOver():void {
			mc.removeEventListener(Event.ENTER_FRAME, ENTER_FRAME );
			carrot.removeEvent();
			
			mc.carrot_mc.x = carrotX;
			mc.carrot_mc.y = carrotY;
			mc.carrot_mc.gotoAndStop(1);
			
			mc.timeOver_mc.visible = true;
			
			Global_Properties.carrotJuice = count;
			
			var timer:Timer = new Timer( 2000, 1 );
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, function (e:TimerEvent):void {
				timer.removeEventListener(TimerEvent.TIMER_COMPLETE, arguments.callee );
				main.bombInit(); // 게임오버
			});
			timer.start();
		}
		
		//당근 놓으믄 원위치
		public function asYouWere():void {
			mc.carrot_mc.arrow_mc.visible = true;
			mc.carrot_mc.x = carrotX;
			mc.carrot_mc.y = carrotY;
			
			mc.carrotShadow_mc.visible = true;
			carrot.shadowHit = false;
		}
		
		private function mCarrotVisible( _num:int ):void {
			SoundCollection.carrotDropSound();
			
			mc.mCarrot_mc.mc23_mc.visible = false;
			mc.mCarrot_mc.mc4_mc.visible = false;
			mc.mCarrot_mc.mc5_mc.visible = false;
			mc.mCarrot_mc.mc6_mc.visible = false;
			
			switch (_num) {
				case 2: mc.mCarrot_mc.mc23_mc.visible = true; mc.mCarrot_mc.mc23_mc.gotoAndPlay(2);
				break;
				case 3: mc.mCarrot_mc.mc23_mc.visible = true; mc.mCarrot_mc.mc23_mc.gotoAndPlay(2);
				break;
				case 4: mc.mCarrot_mc.mc4_mc.visible = true; mc.mCarrot_mc.mc4_mc.gotoAndPlay(2);
				break;
				case 5: mc.mCarrot_mc.mc5_mc.visible = true; mc.mCarrot_mc.mc5_mc.gotoAndPlay(2);
				break;
				case 6: mc.mCarrot_mc.mc6_mc.visible = true; mc.mCarrot_mc.mc6_mc.gotoAndPlay(2);
				break;
				default:
			}
		}
		
		//다 갈은 당근 없애고 새당근으로 교체
		private function changeCarrot():void {
			mc.carrot_mc.visible = false;
			//mc.carrot_mc.visible = true;
			
			mc.carrot_mc.gotoAndStop(1);
			mc.carrot_mc.x = carrotX;
			mc.carrot_mc.y = carrotY;
			
			carrotCount = 0;
			carrotHitLock = true;
			
			carrot.removeEvent();
			carrot.init();
			
			mc.carrotShadow_mc.visible = true;
			mc.carrot_mc.arrow_mc.visible = true;
			//mc.carrot_mc.visible = true;
			mc.mCarrot_mc.visible = true;
			mc.mCarrot_mc.mc23_mc.mc23_mc.cursor_mc.visible = false;
			mc.mCarrot_mc.mc4_mc.mc4_mc.cursor_mc.visible = false;
			mc.mCarrot_mc.mc5_mc.mc5_mc.cursor_mc.visible = false;
			mc.mCarrot_mc.mc6_mc.mc6_mc.cursor_mc.visible = false;
			
			if ( grindedCarrot == 1 || grindedCarrot == 2 ) mCarrotVisible(2);
			if ( grindedCarrot == 3 ) mCarrotVisible(4);
			if ( grindedCarrot == 4 ) mCarrotVisible(5);
			if ( grindedCarrot == 5 ) mCarrotVisible(6);
		}
		
		// 떨어지는 당근 잡기.
		private function mCarrotMOUSE_DOWN(e:MouseEvent):void {
			if ( e.type == MouseEvent.MOUSE_DOWN ) {
				SoundCollection.catchSound();
				
				mc.carrot_mc.x = mc.mouseX;
				mc.carrot_mc.y = mc.mouseY;
				
				carrot.MOUSE_DOWN();
				
				mc.mCarrot_mc.visible = false;
				mc.carrot_mc.visible = true;
			}else if ( e.type == MouseEvent.ROLL_OUT ) {
				MovieClip(e.target).parent["cursor_mc"].visible = false;
			}else if ( e.type == MouseEvent.ROLL_OVER ) {
				MovieClip(e.target).parent["cursor_mc"].x = MovieClip(e.target).parent.mouseX;
				MovieClip(e.target).parent["cursor_mc"].y = MovieClip(e.target).parent.mouseY;
				MovieClip(e.target).parent["cursor_mc"].visible = true;
			}
		}
		private function mCarrot_END(e:Event):void {
			mc.mCarrot_mc.visible = false;
			mc.carrot_mc.visible = true;
		}
		
		//입술에 당근 묻었다.
		private function BuriedOnTheLip():void {
			SoundCollection.ahOhSound();
			buriedCount++;
			buriedManager( buriedCount );
			//mc.buried_mc.gotoAndStop(buriedCount + 1);
			
			if ( buriedCount === STAINED ) { //입주위에 당근 3번 묻었을때...
				buriedCount = 0;
				
				carrot.removeEvent();
				asYouWere();
				exclamationMark(STAINED);
				//moveTongue();
				//buriedManager( buriedCount );
			}
		}
		
		//느낌표 뜨기.
		private function exclamationMark( _num:int ):void {
			switch (_num) {
				case 1: mc.buried_mc.level1_mc.visible = true; mc.buried_mc.level1_mc.gotoAndStop(1);
				break;
				case 2: mc.buried_mc.level2_mc.visible = true; mc.buried_mc.level2_mc.gotoAndStop(1);
				break;
				case 3: mc.buried_mc.level3_mc.visible = true; mc.buried_mc.level3_mc.gotoAndStop(1);
				break;
				case 4: mc.buried_mc.level4_mc.visible = true; mc.buried_mc.level4_mc.gotoAndStop(1);
				break;
				case 5: mc.buried_mc.level5_mc.visible = true; mc.buried_mc.level5_mc.gotoAndStop(1);
				break;
				default:
			}
			var timers:Timer = new Timer( 1000, 1 );
			timers.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent):void {
				timers.removeEventListener(TimerEvent.TIMER_COMPLETE, arguments.callee );
				buriedManager( 0 );
				moveTongue();
			});
			timers.start();
		}
		
		//입닫고 혓바닥으로 당근묻은거 닦기.
		private function moveTongue():void {
			SoundCollection.tongueSound();
			
			closedMouth = true;
			carrot.mouseEnable = false;
			mc.carrotShadow_mc.visible = false;
			mc.carrot_mc.arrow_mc.visible = false;
			mc.mouth_mc.arrow1_mc.visible = false;
			mc.mouth_mc.arrow2_mc.visible = false;
			
			mc.mouth_mc.tongue_mc.gotoAndPlay(2);
		}
		//프레임에 이벤트 있음. 혓바닥으로 당근 묻은거 닦기 끝.
		private function moveTongue_END(e:Event):void {
			closedMouth = false;
			carrot.mouseEnable = true;
			mc.carrotShadow_mc.visible = true;
			mc.carrot_mc.arrow_mc.visible = true;
			
			if ( downToothHit ) {
				mc.mouth_mc.arrow1_mc.visible = true;
			}else {
				mc.mouth_mc.arrow2_mc.visible = true;
			}
			
			carrot.init();
			
		}
		
		private function buriedManager( _num:int ):void {
			mc.buried_mc.level1_mc.visible = false;
			mc.buried_mc.level2_mc.visible = false;
			mc.buried_mc.level3_mc.visible = false;
			mc.buried_mc.level4_mc.visible = false;
			mc.buried_mc.level5_mc.visible = false;
			
			switch ( _num ) {
				case 0 : 
				break;
				case 1 : mc.buried_mc.level1_mc.gotoAndPlay(1); mc.buried_mc.level1_mc.visible = true;
				break;
				case 2 : mc.buried_mc.level2_mc.gotoAndPlay(1); mc.buried_mc.level2_mc.visible = true;
				break;
				case 3 : mc.buried_mc.level3_mc.gotoAndPlay(1); mc.buried_mc.level3_mc.visible = true;
				break;
				case 4 : mc.buried_mc.level4_mc.gotoAndPlay(1); mc.buried_mc.level4_mc.visible = true;
				break;
				case 5 : mc.buried_mc.level5_mc.gotoAndPlay(1); mc.buried_mc.level5_mc.visible = true;
				break;
				default:
			}
		}
		
		private function zeroFormatter( _num:int ):String {
			var str:String;
			if ( _num < 10 ) {
				str = "00" + _num;
			}else if ( _num < 100 ) {
				str = "0" + _num;
			}else if ( _num >= 100 ) {
				str = String( _num );
			}
			return str;
		}
		
		private function numberBoard( _cnt:Number, _mc:MovieClip ):void {
			var str:String;
			var num10000:String;
			var num1000:String;
			var num100:String;
			var num10:String;
			var num1:String;
			
			if ( _cnt < 10 ) {
				_mc.num1_mc.gotoAndStop( _cnt +1 );
			}else if ( _cnt >= 10 && _cnt < 100 ) {
				str = String( _cnt );
				num10 = str.substr(0, 1);
				num1 = str.substr(1, 1);
				
				if( Number(num10) === 0 ) _mc.num10_mc.gotoAndStop( 1 );
				else _mc.num10_mc.gotoAndStop( Number(num10)+1 );
				
				if( Number(num1) === 0 ) _mc.num1_mc.gotoAndStop( 1 );
				else _mc.num1_mc.gotoAndStop( Number(num1)+1 );
			}else if ( _cnt >= 100 && _cnt < 1000 ) {
				str = String( _cnt );
				num100 = str.substr(0, 1);
				num10 = str.substr(1, 1);
				num1 = str.substr(2, 1);
				
				if( Number(num100) === 0 ) _mc.num100_mc.gotoAndStop( 1 );
				else _mc.num100_mc.gotoAndStop( Number(num100) + 1 );
				
				if( Number(num10) === 0 ) _mc.num10_mc.gotoAndStop( 1 );
				else _mc.num10_mc.gotoAndStop( Number(num10)+1 );
				
				if( Number(num1) === 0 ) _mc.num1_mc.gotoAndStop( 1 );
				else _mc.num1_mc.gotoAndStop( Number(num1)+1 );
			}else if ( _cnt >= 1000 && _cnt < 10000 ) {
				str = String( _cnt );
				num1000 = str.substr(0, 1);
				num100 = str.substr(1, 1);
				num10 = str.substr(2, 1);
				num1 = str.substr(3, 1);
				
				if( Number(num1000) === 0 ) _mc.num1000_mc.gotoAndStop( 1 );
				else _mc.num1000_mc.gotoAndStop( Number(num1000) + 1 );
				
				if( Number(num100) === 0 ) _mc.num100_mc.gotoAndStop( 1 );
				else _mc.num100_mc.gotoAndStop( Number(num100) + 1 );
				
				if( Number(num10) === 0 ) _mc.num10_mc.gotoAndStop( 1 );
				else _mc.num10_mc.gotoAndStop( Number(num10)+1 );
				
				if( Number(num1) === 0 ) _mc.num1_mc.gotoAndStop( 1 );
				else _mc.num1_mc.gotoAndStop( Number(num1)+1 );
			}else if ( _cnt >= 10000 && _cnt < 100000 ) {
				str = String( _cnt );
				num10000 = str.substr(0, 1);
				num1000 = str.substr(1, 1);
				num100 = str.substr(2, 1);
				num10 = str.substr(3, 1);
				num1 = str.substr(4, 1);
				
				if( Number(num10000) === 0 ) _mc.num10000_mc.gotoAndStop( 1 );
				else _mc.num10000_mc.gotoAndStop( Number(num10000) + 1 );
				
				if( Number(num1000) === 0 ) _mc.num1000_mc.gotoAndStop( 1 );
				else _mc.num1000_mc.gotoAndStop( Number(num1000) + 1 );
				
				if( Number(num100) === 0 ) _mc.num100_mc.gotoAndStop( 1 );
				else _mc.num100_mc.gotoAndStop( Number(num100) + 1 );
				
				if( Number(num10) === 0 ) _mc.num10_mc.gotoAndStop( 1 );
				else _mc.num10_mc.gotoAndStop( Number(num10)+1 );
				
				if( Number(num1) === 0 ) _mc.num1_mc.gotoAndStop( 1 );
				else _mc.num1_mc.gotoAndStop( Number(num1)+1 );
			}
		}
		
		private function scoreInin( _mc:MovieClip ):void {
			 _mc.num10000_mc.gotoAndStop(1);
			 _mc.num1000_mc.gotoAndStop(1);
			 _mc.num100_mc.gotoAndStop(1);
			 _mc.num10_mc.gotoAndStop(1);
			 _mc.num1_mc.gotoAndStop(1);
		}
		
		private function bonusInit( _mc:MovieClip ):void {
			 _mc.num100_mc.gotoAndStop(1);
			 _mc.num10_mc.gotoAndStop(1);
			 _mc.num1_mc.gotoAndStop(1);
		}
		
		private function addEvent():void {
			mc.startCount_mc.addEventListener( "startCount_END", function(e:Event):void {
				startGame();
					
				//테스트용 
				//Global_Properties.carrotJuice = 6;
				//nextGame();
			});
			
			mc.mouth_mc.tongue_mc.addEventListener( "moveTongue_END", moveTongue_END );//frame dispatch
			
			mc.mCarrot_mc.mc23_mc.addEventListener("mCarrot_END", mCarrot_END ); //frame dispatch
			mc.mCarrot_mc.mc4_mc.addEventListener("mCarrot_END", mCarrot_END ); //frame dispatch
			mc.mCarrot_mc.mc5_mc.addEventListener("mCarrot_END", mCarrot_END ); //frame dispatch
			mc.mCarrot_mc.mc6_mc.addEventListener("mCarrot_END", mCarrot_END ); //frame dispatch
			
			
			mc.mCarrot_mc.mc23_mc.mc23_mc.hand_mc.addEventListener(MouseEvent.MOUSE_DOWN, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc4_mc.mc4_mc.hand_mc.addEventListener(MouseEvent.MOUSE_DOWN, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc5_mc.mc5_mc.hand_mc.addEventListener(MouseEvent.MOUSE_DOWN, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc6_mc.mc6_mc.hand_mc.addEventListener(MouseEvent.MOUSE_DOWN, mCarrotMOUSE_DOWN ); //frame dispatch
			
			mc.mCarrot_mc.mc23_mc.mc23_mc.hand_mc.addEventListener(MouseEvent.ROLL_OUT, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc4_mc.mc4_mc.hand_mc.addEventListener(MouseEvent.ROLL_OUT, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc5_mc.mc5_mc.hand_mc.addEventListener(MouseEvent.ROLL_OUT, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc6_mc.mc6_mc.hand_mc.addEventListener(MouseEvent.ROLL_OUT, mCarrotMOUSE_DOWN ); //frame dispatch
			
			mc.mCarrot_mc.mc23_mc.mc23_mc.hand_mc.addEventListener(MouseEvent.ROLL_OVER, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc4_mc.mc4_mc.hand_mc.addEventListener(MouseEvent.ROLL_OVER, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc5_mc.mc5_mc.hand_mc.addEventListener(MouseEvent.ROLL_OVER, mCarrotMOUSE_DOWN ); //frame dispatch
			mc.mCarrot_mc.mc6_mc.mc6_mc.hand_mc.addEventListener(MouseEvent.ROLL_OVER, mCarrotMOUSE_DOWN ); //frame dispatch
			
		}
		
		// 게임성공. 다음게임 넘어가기.
		private function clearGame():void {
			SoundCollection.clearSound();
			
			timer.stop();
			carrot.removeEvent();
			mc.carrot_mc.x = carrotX;
			mc.carrot_mc.y = carrotY;
			mc.carrot_mc.gotoAndStop(1);
			mc.clear_mc.visible = true;
			
			bonusScore();
			
			Global_Properties.carrotJuice = grindedCarrot; // 갈은 당근 갯수 
			Global_Properties.count = count; // 갈은 당근 게이지 
			//Global_Properties.score = score;
			
			var timers:Timer = new Timer( 2000, 1 );
			timers.addEventListener(TimerEvent.TIMER_COMPLETE, function (e:TimerEvent):void {
				timers.removeEventListener(TimerEvent.TIMER_COMPLETE, arguments.callee );
				nextGame();
			});
			timers.start();
		}
		
		private function bonusScore():void {
			SoundCollection.speedBonusSound();
			
			var bonus:int = (timer.sec + ( timer.milSec / 1000 )) * 20;
			
			Global_Properties.score = score + bonus;
			//Global_Properties.score = 897932397;
			
			numberBoard( (score + bonus), mc.score_mc );
			
			numberBoard( bonus, mc.bonus_mc.score_mc );
			mc.bonus_mc.gotoAndPlay(2);
		}
		
		// 게임실패. 다음게임 넘어가기.
		private function nextGame():void {
			main.viewChange( "game2_mc" );
			main.game2Init();
			
		}
	}

}